const path = require('path')
const webpack = require('webpack')
//gzip压缩
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const config = {
  // 基本路径
  publicPath: '/',
  outputDir: 'dist',
  lintOnSave: true,
  //打包取消生成map文件
  productionSourceMap: false,

  devServer: {
    open: true,
    host: process.env.VUE_APP_HOST,
    port: process.env.VUE_APP_PORT,
  },
  css: {
    requireModuleExtension: true,
    sourceMap: true,
    loaderOptions: {
      scss: {
        additionalData(content, loaderContext) {
          const {
            resourcePath,
            rootContext
          } = loaderContext
          const relativePath = path.relative(rootContext, resourcePath)
          if (
            relativePath.replace(/\\/g, '/') !== 'src/style/common.scss'
          ) {
            return '@import "~@/style/common.scss";' + content
          }
          return content
        },
      },
    },
  },
  configureWebpack: {
    entry: {
      app: './src/main.js'
    },
    //CDN引入配置
    externals: {
      'vue': 'Vue',
      'ElementUI': 'ELEMENT',
    },
    plugins: [
      new webpack.ProvidePlugin({
        'window.Quill': 'quill/dist/quill.js',
        'Quill': 'quill/dist/quill.js',
      }),
    ]
  },
}
//正式环境执行去除conson.log 
if (process.env.NODE_ENV === 'production') {
  config.configureWebpack.plugins.concat([
     new CompressionWebpackPlugin({
        test: /\.js$|\.html$|.\css/,
        threshold: 8192,
        minRatio: 0.8,
      })
  ])
}

module.exports = config